import { reactive, ref } from 'vue'
import { DtlParamManager } from '@/utils/common'
import { PmsParam } from '@longnows/lib'
import type { DpmObs, DpmPipe } from '../util'
import { message } from 'ant-design-vue'
export const useHeaderActions = (dpm: DtlParamManager<DpmPipe, DpmObs>) => {
  const pmsParam = PmsParam.getInstance()
  //获取按钮配置
  const getActions = () => pmsParam.getActions('swagger_helper_body_list', '表头')
  const headerActionConfig = ref<any[]>([])
  getActions().then((res) => {
    headerActionConfig.value = res
  })
  const headerActionFun = reactive({
    save: async () => {
      let { wrapMethods } = await dpm.formManager.getFormContext('header')
      console.log('🚀 ~ useHeaderActions ~ values:', wrapMethods.getFieldsValue())
    },
  })

  return {
    headerActionConfig,
    headerActionFun,
  }
}

export const useBodyActions = (dpm, commonListRef, openBodyInfoModal) => {
  console.log('🚀 ~ useActions ~ dpm:', dpm)
  const getSelectRowKeys = (): string[] => {
    return commonListRef.value?.getSelectRowKeys() || []
  }

  const afterGetActions = (actions: Recordable[]) => {
    return actions.map((item) => {
      return {
        ...item,
      }
    })
  }
  const headerBodyActionFun = reactive({
    add: () => {
      openBodyInfoModal()
    },
    delete: () => {
      const uidList = getSelectRowKeys()
      if (!uidList.length) {
        message.warning('请选择要删除的行')
        return
      }
    },
  })

  return {
    headerBodyActionFun,
    afterGetActions,
  }
}
